home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / strpchrt.arj / EX_STEP.C < prev    next >
Text File  |  1993-07-10  |  3KB  |  116 lines

  1. /*
  2.    Strip Chart Library Example for drawing step functions.
  3.  
  4.    Copyright (c) 1993 by Christopher Lim.  All rights reserved.
  5. */
  6.  
  7. #include "sc.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <conio.h>
  11.  
  12. /*------------------------------------------------------------*/
  13.  
  14. void GetPrinterType(unsigned char *printerType, unsigned char *printerRes,
  15.    char **s)
  16. {
  17.    int c;
  18.    unsigned char i,j;
  19.  
  20.    printf("Select printer type and resolution code: \n");
  21.    printf("[1] 9 PIN LOW RES\n");
  22.    printf("[2] 9 PIN HIGH RES\n");
  23.    printf("[3] 24 PIN LOW RES\n");
  24.    printf("[4] 24 PIN HIGH RES\n");
  25.    printf("Select code [1,2,3 or 4]: ");
  26.    c = getch();
  27.    printf("%c\n",c);
  28.    switch (c)
  29.    {
  30.         case '1': i = SC_9PIN; j = SC_LOW_RES;
  31.              *s = "9 PIN LOW RES";
  32.              break;
  33.         case '2': i = SC_9PIN; j = SC_HIGH_RES;
  34.              *s = "9 PIN HIGH RES";
  35.              break;
  36.         case '3': i = SC_24PIN; j = SC_LOW_RES;
  37.              *s = "24 PIN LOW RES";
  38.              break;
  39.         case '4': i = SC_24PIN; j = SC_HIGH_RES;
  40.              *s = "24 PIN HIGH RES";
  41.              break;
  42.         default:
  43.              printf("Aborted\n");
  44.              exit(1);
  45.    }
  46.    printf("%s\n",*s);
  47.    *printerType = i;
  48.    *printerRes = j;
  49.    return;
  50. }
  51.  
  52. /*------------------------------------------------------------*/
  53.  
  54. void ErrorTrap(char *msg)
  55. {
  56.     printf("%s\n",msg);
  57.     exit(1);
  58. }
  59.  
  60. /*------------------------------------------------------------*/
  61.  
  62. void main()
  63. {
  64.    int i;
  65.    int error;
  66.    double level;
  67.    char *s;
  68.    unsigned char printerType, printerRes;
  69.    SC_WINDOW *w;
  70.  
  71.  
  72.    if (!SC_PrinterReady(LPT1))
  73.    {
  74.       printf("Printer at LPT1 is not ready!\n");
  75.       exit(1);
  76.    }
  77.  
  78.    GetPrinterType(&printerType, &printerRes, &s);
  79.  
  80.    SC_SetErrorTrap(ErrorTrap);
  81.  
  82.    /* Initialize: use metric units, 20 cm paper width,
  83.       plot speed of 2 cm/sec
  84.    */
  85.    SC_Init(LPT1, printerType, printerRes, CENTIMETERS, 20.0, 2.0, &error);
  86.  
  87.    /* Add a trace window:
  88.       0.5 cm from top of page, 5.0 cm height,
  89.       real world coordinates range from -1.0 to 1.0,
  90.       draw a border around the trace
  91.    */
  92.    w = SC_AddTraceWindow(0.5, 5.0, -1.0, 1.0, SCF_BORDER, &error);
  93.  
  94.    /* draw steps */
  95.    level = -1.0; /* first point */
  96.    for (i=0; i <= 10; i++)
  97.    {
  98.       /* Draw a horizontal line at current level */
  99.       SC_Trace(w,level,&error);
  100.       SC_Draw();
  101.  
  102.       /* change level */
  103.       level += 1.0;
  104.       if (level > 1.0)
  105.          level = -1.0; /* wrap */
  106.  
  107.       /* Draw vertical line to new level */
  108.       SC_Trace(w,level,&error);
  109.       SC_Draw();
  110.  
  111.       SC_Advance(1.0); /* advance paper 1.0 sec == 2 cm */
  112.    }
  113.  
  114.    SC_Close(); /* terminate strip chart */
  115. }
  116.